extends Node

signal  onPlayerDataChange()

const character_data_path = "user://character_data.json"

var default_character_data = {
	"character_name": "默认角色",
	"info":{
		"level": 1,
		"realm": "不入流",
		"experience": "0/100"	
		},
	"attr":{
	  "attack": 10,
	  "defense": 5,
	  "speed": 10,
	  "inner_force": "0/100",
	},
	"equipment":{
		 "weapon": "初始剑",
		 "armor": "初始衣",
	},
	"status":{
	   "status": "健康",
	   "buff": "无"
	}
}

## 角色数据
var _character_data = {}

## 加载角色数据
func load_character_data():
	_character_data = CommUtils.load_data(character_data_path);
	if _character_data == null:
		_character_data = default_character_data
		save_character_data() 
	emit_signal("onPlayerDataChange")
	
	
func get_character_data():
	return _character_data	
	
func save_character_data():
	CommUtils.save_data(character_data_path,_character_data)
	

func update_character_data(key:String,value):
	if _character_data.has(key):
		_character_data[key] = value
		save_character_data()  # 每次更新后保存数据
		emit_signal("onPlayerDataChange")
